﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using THSLib;
using THSERP.BusinessEntities;
using THSERP.BaseProvider;
namespace THSERP
{
    public partial class ModuleSearchScreen : DevExpress.XtraEditors.XtraForm
    {
        public BaseModuleERP module;
        private THSTextBox fld_txtCriteriaName;
        private THSLabel THSLabel1;
        private THSMemoEdit fld_mmDesciptions;
        private THSLabel THSLabel2;
        private THSButton fld_btnOK;
        private THSButton fld_btnCancel;
        public ModuleSearchScreen()
        {
            InitializeComponent();
        }
        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ModuleSearchScreen));
            this.panelControl1 = new DevExpress.XtraEditors.PanelControl();
            this.fld_btnOK = new THSERP.BaseProvider.THSButton(this.components);
            this.fld_btnCancel = new THSERP.BaseProvider.THSButton(this.components);
            this.fld_splCriteria = new DevExpress.XtraEditors.SplitContainerControl();
            this.THSLabel2 = new THSERP.BaseProvider.THSLabel(this.components);
            this.THSLabel1 = new THSERP.BaseProvider.THSLabel(this.components);
            this.fld_mmDesciptions = new THSERP.BaseProvider.THSMemoEdit(this.components);
            this.fld_txtCriteriaName = new THSERP.BaseProvider.THSTextBox(this.components);
            ((System.ComponentModel.ISupportInitialize)(this.panelControl1)).BeginInit();
            this.panelControl1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.fld_splCriteria)).BeginInit();
            this.fld_splCriteria.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.fld_mmDesciptions.Properties)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_txtCriteriaName.Properties)).BeginInit();
            this.SuspendLayout();
            // 
            // panelControl1
            // 
            this.panelControl1.Controls.Add(this.fld_btnOK);
            this.panelControl1.Controls.Add(this.fld_btnCancel);
            this.panelControl1.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.panelControl1.Location = new System.Drawing.Point(0, 283);
            this.panelControl1.Name = "panelControl1";
            this.panelControl1.Size = new System.Drawing.Size(618, 41);
            this.panelControl1.TabIndex = 0;
            // 
            // fld_btnOK
            // 
            this.fld_btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.fld_btnOK.Location = new System.Drawing.Point(450, 9);
            this.fld_btnOK.Name = "fld_btnOK";
            this.fld_btnOK.Screen = null;
            this.fld_btnOK.Size = new System.Drawing.Size(75, 23);
            this.fld_btnOK.TabIndex = 1;
            this.fld_btnOK.Text = "OK";
            this.fld_btnOK.THSComment = null;
            this.fld_btnOK.THSFieldGroup = null;
            this.fld_btnOK.THSFieldRelation = null;
            this.fld_btnOK.THSPrivilege = null;
            this.fld_btnOK.Click += new System.EventHandler(this.fld_btnOK_Click);
            // 
            // fld_btnCancel
            // 
            this.fld_btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.fld_btnCancel.Location = new System.Drawing.Point(531, 9);
            this.fld_btnCancel.Name = "fld_btnCancel";
            this.fld_btnCancel.Screen = null;
            this.fld_btnCancel.Size = new System.Drawing.Size(75, 23);
            this.fld_btnCancel.TabIndex = 0;
            this.fld_btnCancel.Text = "Cancel";
            this.fld_btnCancel.THSComment = null;
            this.fld_btnCancel.THSFieldGroup = null;
            this.fld_btnCancel.THSFieldRelation = null;
            this.fld_btnCancel.THSPrivilege = null;
            this.fld_btnCancel.Click += new System.EventHandler(this.fld_btnCancel_Click);
            // 
            // fld_splCriteria
            // 
            this.fld_splCriteria.Dock = System.Windows.Forms.DockStyle.Fill;
            this.fld_splCriteria.Horizontal = false;
            this.fld_splCriteria.Location = new System.Drawing.Point(0, 0);
            this.fld_splCriteria.Name = "fld_splCriteria";
            this.fld_splCriteria.Panel1.Controls.Add(this.THSLabel2);
            this.fld_splCriteria.Panel1.Controls.Add(this.THSLabel1);
            this.fld_splCriteria.Panel1.Controls.Add(this.fld_mmDesciptions);
            this.fld_splCriteria.Panel1.Controls.Add(this.fld_txtCriteriaName);
            this.fld_splCriteria.Panel1.Text = "Panel1";
            this.fld_splCriteria.Panel2.Text = "Panel2";
            this.fld_splCriteria.Size = new System.Drawing.Size(618, 283);
            this.fld_splCriteria.TabIndex = 1;
            // 
            // THSLabel2
            // 
            this.THSLabel2.Location = new System.Drawing.Point(4, 53);
            this.THSLabel2.Name = "THSLabel2";
            this.THSLabel2.Screen = null;
            this.THSLabel2.Size = new System.Drawing.Size(27, 13);
            this.THSLabel2.TabIndex = 3;
            this.THSLabel2.Text = "Mô tả";
            this.THSLabel2.THSComment = null;
            this.THSLabel2.THSDataMember = null;
            this.THSLabel2.THSDataSource = null;
            this.THSLabel2.THSFieldGroup = null;
            this.THSLabel2.THSFieldRelation = null;
            this.THSLabel2.THSPrivilege = null;
            // 
            // THSLabel1
            // 
            this.THSLabel1.Location = new System.Drawing.Point(4, 19);
            this.THSLabel1.Name = "THSLabel1";
            this.THSLabel1.Screen = null;
            this.THSLabel1.Size = new System.Drawing.Size(63, 13);
            this.THSLabel1.TabIndex = 2;
            this.THSLabel1.Text = "Tên điều kiện";
            this.THSLabel1.THSComment = null;
            this.THSLabel1.THSDataMember = null;
            this.THSLabel1.THSDataSource = null;
            this.THSLabel1.THSFieldGroup = null;
            this.THSLabel1.THSFieldRelation = null;
            this.THSLabel1.THSPrivilege = null;
            // 
            // fld_mmDesciptions
            // 
            this.fld_mmDesciptions.Location = new System.Drawing.Point(78, 41);
            this.fld_mmDesciptions.Name = "fld_mmDesciptions";
            this.fld_mmDesciptions.Screen = null;
            this.fld_mmDesciptions.Size = new System.Drawing.Size(537, 49);
            this.fld_mmDesciptions.TabIndex = 1;
            this.fld_mmDesciptions.THSComment = null;
            this.fld_mmDesciptions.THSDataMember = null;
            this.fld_mmDesciptions.THSDataSource = null;
            this.fld_mmDesciptions.THSError = null;
            this.fld_mmDesciptions.THSFieldGroup = null;
            this.fld_mmDesciptions.THSFieldRelation = null;
            this.fld_mmDesciptions.THSPrivilege = null;
            this.fld_mmDesciptions.THSPropertyName = null;
            // 
            // fld_txtCriteriaName
            // 
            this.fld_txtCriteriaName.Location = new System.Drawing.Point(78, 16);
            this.fld_txtCriteriaName.Name = "fld_txtCriteriaName";
            this.fld_txtCriteriaName.Screen = null;
            this.fld_txtCriteriaName.Size = new System.Drawing.Size(323, 20);
            this.fld_txtCriteriaName.TabIndex = 0;
            this.fld_txtCriteriaName.THSComment = null;
            this.fld_txtCriteriaName.THSDataMember = null;
            this.fld_txtCriteriaName.THSDataSource = null;
            this.fld_txtCriteriaName.THSError = null;
            this.fld_txtCriteriaName.THSFieldGroup = null;
            this.fld_txtCriteriaName.THSFieldRelation = null;
            this.fld_txtCriteriaName.THSPrivilege = null;
            this.fld_txtCriteriaName.THSPropertyName = null;
            this.fld_txtCriteriaName.Validated += new System.EventHandler(this.fld_txtCriteriaName_Validated);
            // 
            // ModuleSearchScreen
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(618, 324);
            this.Controls.Add(this.fld_splCriteria);
            this.Controls.Add(this.panelControl1);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "ModuleSearchScreen";
            this.Text = "Tìm kiếm";
            this.Load += new System.EventHandler(this.ModuleSearchScreen_Load);
            ((System.ComponentModel.ISupportInitialize)(this.panelControl1)).EndInit();
            this.panelControl1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.fld_splCriteria)).EndInit();
            this.fld_splCriteria.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.fld_mmDesciptions.Properties)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_txtCriteriaName.Properties)).EndInit();
            this.ResumeLayout(false);

        }
        /// <summary>
        /// check exists criteria by Name,module and User
        /// </summary>
        /// <returns>HieuNH_23/05/2010</returns>
        /// 
        public bool IsExistCriteriaName()
        {
            bool isExist = false;
            if (new ADCriteriasController().IsExistCriteriaName(CriteriaName.Text, ((BaseModuleERP)this.module).ModuleID, THSApp.CurrentUsersInfo.ADUserID))
            {
                isExist = true;
                MessageBox.Show("Already exists criteria name", "Infomation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            return isExist;
        }

        #endregion

        private DevExpress.XtraEditors.PanelControl panelControl1;
        private DevExpress.XtraEditors.SplitContainerControl fld_splCriteria;
        #region Properties
        public THSTextBox CriteriaName
        {
            get { return fld_txtCriteriaName; }
            set { fld_txtCriteriaName = value; }
        }
        public DevExpress.XtraEditors.PanelControl CriteriaSection
        {
            get { return fld_splCriteria.Panel2; }
            // set { fld_splContainer.Panel2 = value; }
        }
        public DevExpress.XtraEditors.PanelControl GeneralSection
        {
            get { return fld_splCriteria.Panel1; }
        }
        public THSMemoEdit CriteriaDescription
        {
            get { return fld_mmDesciptions; }
            set { fld_mmDesciptions = value; }
        }

        #endregion

        private void fld_btnOK_Click(object sender, EventArgs e)
        {
            if (IsExistCriteriaName())
                return;
            ((BaseModuleERP)module).SearchByCriteria();
            this.Close();
        }

        private void fld_btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ModuleSearchScreen_Load(object sender, EventArgs e)
        {
            fld_mmDesciptions.Text = String.Empty;
            fld_txtCriteriaName.Text = String.Empty;
        }

        private void fld_txtCriteriaName_Validated(object sender, EventArgs e)
        {
            IsExistCriteriaName();
        }
        #region Utilities
        
        #endregion
    }
}